home *** CD-ROM | disk | FTP | other *** search
- /* realloc.c --- p. 139 */
- #include <stdio.h>
- #include <stdlib.h>
- #include <alloc.h>
- main()
- {
- unsigned char *buffer;
- /* Allocate room for string and check for NULL */
- if( (buffer = (char *)malloc(10)) == NULL)
- {
- printf("allocation Failed. \n");
- exit(0);
- }
- printf("Buffer allocated. Enter string to store: ");
- gets(buffer);
- printf("\nYou entered: %s\n", buffer);
- /* Now enlarge the size of buffer and redisplay string */
- if( (buffer = (char *)realloc((void *)buffer, 80)) == NULL )
- {
- printf("Reallocation Failed.\n");
- exit(0);
- }
- printf("Buffer still contains: %s\n", buffer);
- }